import java.util.concurrent.BlockingDeque;

/**
 * @Auther: zch
 * @Date: 2019/6/27 15:30
 * @Description:
 */
public class Worker extends Thread{
    private Runnable task;
    private boolean alive;

    public Worker(Runnable task) {
        this.task = task;
    }

    public Runnable getTask() {
        return task;
    }

    public void setTask(Runnable task) {
        this.task = task;
    }

    private Runnable getTask(BlockingDeque<Runnable> taskQueue){
        try {
            Runnable task=taskQueue.take();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        if(task!=null){
            this.setTask(task);
        }
    }

    @Override
    public void run() {
       runWorker();
    }

    private void runWorker(){

        while (task!=null){
          task.run();
          task=null;
          System.out.println("啊哈哈");
        }
    }


    public static void main(String[] args) {
        Runnable task=new Runnable() {
            @Override
            public void run() {
                System.out.println("任务……");
            }
        };
        Worker worker=new Worker(task);
        worker.run();//这个线程会里面会掉work里面的run 方法，无限
        try {
            Thread.sleep(3000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        worker.setTask(task);
        t.run();
    }
}
